package com.example.forum.controller;

import com.example.forum.common.AppResult;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import io.swagger.annotations.ApiParam;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

@Api(tags = "测试类的相关接口")
@RestController
@RequestMapping("/test")
public class TestController {

    @ApiOperation("测试接口1：显示hello Spring forum!!!")
    @RequestMapping("/hello")
    public String hello() {
        return "hello Spring forum!!!";
    }


    @ApiOperation("测试接口2：显示抛出 ApplicationException异常")
    @GetMapping("/appException")
    public AppResult testApplicationException() throws Exception {
        throw new Exception("这是一个ApplicationException异常");
    }

    @ApiOperation("测试接口3：显示抛出Exception异常")
    @GetMapping("/exception")
    public AppResult testException() throws Exception {
        throw new Exception("这是一个Exception异常");
    }

    @RequestMapping("/helloByName")
    @ApiOperation("测试接口4：显示hello Spring forum!!!")
    public String helloByName(@ApiParam("姓名") String name) {
        return "hello " + name;
    }
}
